//
//  M_NewsDetail.m
//  suRead
//
//  Created by lidi on 15/11/8.
//  Copyright © 2015年 bao. All rights reserved.
//

#import "M_NewsDetail.h"

@implementation M_NewsDetail
+ (NSDictionary *)JSONKeyPathsByPropertyKey
{
    return @{
             @"f_docid":@"docid",
             @"f_title":@"title",
             @"f_catid":@"catid",
             @"f_catname":@"catname",
             @"f_username":@"username",
             @"f_body":@"body",
             @"f_users":@"users",
             @"f_keyword_search":@"keyword_search",
             @"f_hits":@"hits",
             @"f_source":@"source",
             @"f_source_url":@"source_url",
             @"f_type":@"type",
             @"f_images":@"images",
             @"f_apps":@"apps",
             @"f_ptime":@"ptime",
             @"f_commentid":@"commentid",
             @"f_comments":@"comments",
             @"f_commentsUrl":@"commentsUrl",
             @"f_views":@"views",
             @"f_allow_comment":@"allow_comment",
             @"f_relation":@"relation",
             @"f_style":@"style",
             @"f_advinfo":@"advinfo",
             @"f_adv":@"adv",
             @"f_wid":@"wid",
             @"f_service_name":@"service_name",
             @"f_service_img":@"service_img",
             @"f_service_count":@"service_count",
             @"f_is_subscribe":@"is_ subscribe"
             };
}



+ (NSValueTransformer *)f_docidJSONTransformer {
    
    return [MTLValueTransformer transformerUsingForwardBlock:^(NSNumber *value_, BOOL *success, NSError **error){
        
        if (!value_) {
            return @"";
        }
        
        return [NSString stringWithFormat:@"%@",value_];
        
    }];
    
}

+ (NSValueTransformer *)f_imagesJSONTransformer {
    
    return [MTLValueTransformer transformerUsingForwardBlock:^(id value_, BOOL *success, NSError **error){
        
        if (value_ && [value_ isKindOfClass:[NSArray class]]) {
            return value_;
        }
        else {
            return (id)@[];
        }
        
    }];
    
}

+ (NSValueTransformer *)f_ptimeJSONTransformer {
    
    return [MTLValueTransformer transformerUsingForwardBlock:^(NSNumber *value_, BOOL *success, NSError **error){
        
        if (!value_) {
            return @"";
        }
        
        double timeInterval = [value_ doubleValue];
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateStyle:NSDateFormatterMediumStyle];
        [formatter setTimeStyle:NSDateFormatterShortStyle];
        [formatter setDateFormat:@"MM-dd HH:mm"];
        
        //时间戳转时间的方法
        NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:timeInterval];
        NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
        
        return confromTimespStr;
        
    }];
    
}

+ (NSValueTransformer *)f_commentsJSONTransformer {
    
    return [MTLValueTransformer transformerUsingForwardBlock:^(NSNumber *value_, BOOL *success, NSError **error){
        
        if (!value_) {
            return @"0";
        }
        
        return [NSString stringWithFormat:@"%@",value_];
        
    }];
    
}

+ (NSValueTransformer *)f_relationJSONTransformer {
    
    return [MTLValueTransformer transformerUsingForwardBlock:^(NSArray *value_, BOOL *success, NSError **error){
        return [MTLJSONAdapter modelsOfClass:[M_NewsDetailRelation class] fromJSONArray:value_ error:nil];
    }];
    
}
@end
